package org.example.service;

import com.alipay.sofa.rpc.config.ProviderConfig;
import com.alipay.sofa.rpc.config.ServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class SeqServer {

    @Value("${server4.seq.port}")
    private int port;
    @Autowired
    private OrderCmdCache cache;

    @PostConstruct
    public void init() {
        //SOFA RPC
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setPort(port)
                .setProtocol("bolt");

        ProviderConfig<FetchService> providerConfig = new ProviderConfig<>();
        providerConfig.setInterfaceId(FetchService.class.getName());
        providerConfig.setRef(() -> cache.getAll());
        providerConfig.setServer(serverConfig);

        providerConfig.export();
    }
}
